package com.zc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zc.domain.FourPointsItem;
//import com.zc.service.DataService;
import com.zc.service.FaultService;
import com.zc.service.PowerFactorService;
import com.zc.service.PowerService;
import com.zc.service.PresService;
import com.zc.service.TcService;
import com.zc.service.TemService;
import com.zc.service.RedisService;
import com.zc.service.VibService;

@Controller
public class VibController {
	@Autowired
	private VibService vibService;
	@Autowired
	private RedisService redisService;
	
	@RequestMapping(value = "/getSubVibration",method = RequestMethod.POST)
    public @ResponseBody FourPointsItem getSubVibration(){       	
		String key="subVibrationData";
		FourPointsItem subVibrationData=null;
		if(redisService.hasKey(key)){
			subVibrationData=(FourPointsItem) redisService.get(key);
		}		
		else {
			subVibrationData=vibService.getSubVibration();
			redisService.set(key, subVibrationData);
		}
		return subVibrationData;
    }
	
	@RequestMapping(value = "/getMainVibration",method = RequestMethod.POST)
    public @ResponseBody FourPointsItem getMainVibration(){       	
		String key="mainVibrationData";
		FourPointsItem mainVibrationData=null;
		if(redisService.hasKey(key)){
			mainVibrationData=(FourPointsItem) redisService.get(key);
		}		
		else {
			mainVibrationData=vibService.getMainVibration();
			redisService.set(key, mainVibrationData);
		}
		return mainVibrationData;
    }
	
	@RequestMapping(value = "/getMainTodayVib",method = RequestMethod.POST)
    public @ResponseBody List<FourPointsItem> getMainTodayVib(){       	
		return vibService.getTodayVibration(true);
    }
	
	@RequestMapping(value = "/getSubTodayVib",method = RequestMethod.POST)
    public @ResponseBody List<FourPointsItem> getSubTodayVib(){       	
		return vibService.getTodayVibration(false);
    }
}
